﻿/*
 *Copyright(C) 2020 by  GYYX All rights reserved.
 *Unity版本：2018.4.23f1 
 *作者:程一峰  
 *创建日期: 2021-04-08 
 *模块说明：
 *版本: 1.2
*/

using UnityEngine;
using Warfare.FSM;

namespace WarfareEditor.FSM
{
    /// <summary>
    /// 用于节点的划线；
    /// </summary>
    public class FSMZoom_Line : FSMZoom
    {
        protected internal override void OnDestroy() { }

        protected internal override void OnGUI()
        {
            var rootNode = window.CurrentAsset.RootNode;
            DrawNodeLines(rootNode);

            var L = window.CurrentAsset.ListNodes;
            var length = L.Count;
            for (int i = 0; i < length; i++)
            {
                var node = L[i];
                DrawNodeLines(node);
            }
        }

        private void DrawNodeLines(FSMNode node)
        {
            Vector2 startPos, endPos;
            Color col;

            //画线；
            if (node.IsHasSucessNode())
            {
                startPos = node.SucessPoint();
                endPos = node.GetSucessNode(curFsmAsset).TopCenterPoint();
                col = Color.green;
                FSMEditorTool.DrawLine(startPos, endPos, col);
            }

            if (node.IsHasFailedNode())
            {
                startPos = node.FailedPoint();
                endPos = node.GetFailedNode(curFsmAsset).TopCenterPoint();
                col = Color.red;
                FSMEditorTool.DrawLine(startPos, endPos, col);
            }
        }

    }
}